#pragma once

#include <mmsystem.h>
#include "WLRender.h"
#include <d3dx9.h>
#include "WLPrimitive.h"
extern LPDIRECT3D9             g_pD3D; // Used to create the D3DDevice
extern LPDIRECT3DDEVICE9       g_pd3dDevice; // Our rendering device

class WLD3DFrameData
{
public:
	WLD3DFrameData()
	{
		m_pVB = NULL;
		m_iPrimitiveCount = 0;
		m_iVertCount = 0;
		m_VertSize = 0;
		m_pIB = NULL;
		m_TxDiffuse = NULL;
	}
	unsigned int				Revision;
	D3DPRIMITIVETYPE			m_PrimitiveType;
	LPDIRECT3DVERTEXBUFFER9		m_pVB; // Buffer to hold vertices
	unsigned int				m_iPrimitiveCount;
	unsigned int				m_iVertCount;
	unsigned int                m_VertSize;
	DWORD						m_VertexFormat;
	LPDIRECT3DINDEXBUFFER9		m_pIB;
	LPDIRECT3DTEXTURE9			m_TxDiffuse; // Our texture
};

class WLD3DRenderFrame
{
public:
	unsigned int				m_Revision;
	unsigned int				m_FrameID;
	WLMatrix16					m_LocalToWorld;
	D3DPRIMITIVETYPE			DP_Type;
	DWORD						m_VertexFormat;
	std::vector<WLD3DFrameData> m_FrameDataArray;
};

class WLD3DRender : public WLRender
{
public:
	WLD3DRender(){};
	bool InitDevice(HWND hWnd);
	void CleanUp();
	VOID SetupMatrices();
	void PreRender();
	void Render();
	bool UpdateFrame(WLRenderInfo& Info);
	void UpdateAllRenderInfos();
	void UpdateAllFrames();
	WLRenderInfo* GetRenderInfo(unsigned int ActorID);
	WLD3DRenderFrame* GetFrame(unsigned int ActorID);
	void ReleaseFrame(WLD3DRenderFrame* pFrame,ECR_CLEARFLAG ClearFlag);
private:
	std::vector<WLD3DRenderFrame> m_FrameArray; 
};
